package jfuzzyprincepless.zarchive.negotiation.protocols.propositionnetwork;

import java.util.List;

import jfuzzyprincepless.agents.INegotiatingAgent;
import jfuzzyprincepless.zarchive.algorithm.structure.ChainCommand;
import jfuzzyprincepless.zarchive.algorithm.structure.IMultiConstruction;
import jfuzzyprincepless.zarchive.negotiation.IAgentsExporter;
import jfuzzyprincepless.negotiation.IExecutionContext;
import jfuzzyprincepless.negotiation.INegotiationContext;
import jfuzzyprincepless.negotiation.NegotiationUtils;
import jfuzzyprincepless.negotiation.impl.BaseNegotiation;

public class DefaultNegotiation__Q
	extends BaseNegotiation
	implements IAgentsExporter
{
	protected IMultiConstruction multiConstruction;
	protected IAgentsExporter agentsExporter;

	/**
	 * 		DECIDE: [0] may be better to create
	 *
	 *		public class NegotiationData {
	 *			public final INegotiationAgent[] agents;
	 *			public final ICommandConstruction[] commands;
	 *		}
	 *
	 * 		all negotiation constructions == builders of NegotiationData
	 */
	public DefaultNegotiation__Q(
		IMultiConstruction multiConstruction,
		IAgentsExporter agentsExporter
	) {
		this.multiConstruction = multiConstruction;
		this.agentsExporter = agentsExporter;
	}

	@Override
	public void negotiate(INegotiationContext context) {
		context.registerService(this);
		NegotiationUtils.defaultNegotiationIteration(
			getAgents(),
			context
		);
	}

	@Override
	public void execute(IExecutionContext context) {
		ChainCommand.executeCmdList(
			multiConstruction.getCommandsList(),
			context
		);
	}

	@Override
	public List<INegotiatingAgent> getAgents() {
		return agentsExporter.getAgents();
	}
}
